<template>
  <div class="UserAdmin">
    <el-input class="search" placeholder="请输入内容" v-model="search">
      <template #prefix>
        <i class="el-input__icon el-icon-search"></i>
      </template>
    </el-input>
    <div class="searchButto">搜索</div>
  </div>
  <div class="form">
    <div class="heart">
      <div class="heartItem" v-for="(item, index) in hrardList" :key="index">
        {{ item }}
      </div>
    </div>
    <div class="list">
      <div class="itemBox" v-for="(item, index) in userList" :key="index">
        <div class="listitem" v-for="(item2, index2) in item" :key="index2">
          {{ item2 }}
        </div>
        <div class="listitem">
          <!-- <img
              src="@/assets/img/common/update.png"
              @click="upIndex(index)"
            />-->
          <img
            src="@/assets/img/common/delete.png"
            @click="deleteUser(index)"
          />
        </div>
      </div>
    </div>
  </div>
  <div class="mask" v-if="maskShow">
    <div class="context">
      <el-input class="maskInput" placeholder="请输入内容" v-model="search">
      </el-input>
      <el-input class="maskInput" placeholder="请输入内容" v-model="search">
      </el-input>
      <el-input class="maskInput" placeholder="请输入内容" v-model="search">
      </el-input>
      <el-input class="maskInput" placeholder="请输入内容" v-model="search">
      </el-input>
      <div class="queding">提交</div>
      <div class="queding" style="background-color: red">取消</div>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent, onMounted, reactive, toRefs } from "vue";
import { userGetAll, userdelete } from "@/api/sys_user";
export default {
  setup() {
    const state = reactive({
      search: "",
      maskShow: false,
      userList: [{ id: -1 }],
      hrardList: ["性别","id",  "昵称","密码","头像", "账号","操作"],
    });
    const upIndex = () => {
      state.maskShow = true;
    };
    const getUserList = () => {
      userGetAll(new FormData()).then((res: any) => {
        console.log(res);
        state.userList = res.data;
      });
    };
    const deleteUser = (index: number) => {
      userdelete({ id: state.userList[index].id }).then((res) => {
        console.log(res )
        state.userList.splice(index, 1);
      });
    };
    onMounted: {
      getUserList();
    }
    return { ...toRefs(state), upIndex, getUserList, deleteUser };
  },
  components: {},
};
</script>
<style lang="less" scoped>
.mask {
  position: fixed;
  width: 400px;
  background-color: #fff;
  border-radius: 5px;
  z-index: 999;
  left: 35%;
  top: 30%;
  .maskInput {
    margin: 5px 0;
  }
  .queding {
    background-color: @subject_green;
    height: 30px;
    border-radius: 5px;
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 10px;
  }
}
.searchButto {
  width: 100px;
  position: absolute;
  top: 10px;
  left: 300px;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  border-radius: 10px;
  background-color: @subject_green;
  height: 40px;
}
.UserAdmin {
  .search {
    width: 200px;
    position: absolute;
    top: 10px;
    left: 10px;
  }
}
.form {
  overflow-y: scroll;
  height: 500px;
  margin-top: 100px;
  width: 100%;
  .heart {
    width: 80%;
    background-color: @subject_green;
    height: 40px;
    display: flex;
    .heartItem {
      width: 20%;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #fff;
    }
  }
  .list {
    width: 80%;
    background-color: #fff;
    display: flex;
    flex-wrap: wrap;
    .itemBox {
      display: flex;
      width: 100%;
      .listitem {
        width: 20%;
        display: flex;
        height: 40px;
        align-items: center;
        justify-content: center;
        border-bottom: 1px #000 solid;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        img {
          width: 30px;
          height: 30px;
          margin: 5px;
        }
      }
    }
  }
}
</style>